<template>
  <div>
    <div class="text_style">
      <el-card>

        <el-form>
          <el-form-item prop="desc">
            <el-input type="textarea" placeholder="说点什么..." v-model="weibo.content"></el-input>
          </el-form-item>
        </el-form>

        <el-row>
          <el-col :span="18">
            <div class="edit_div">
              <div>

                <el-link :underline="false" @click="routerIndex">
                  <p style="font-size: 20px" class="el-icon-edit"/>
                  <p>编辑</p>
                </el-link>
              </div>
              <div>
                <el-link :underline="false" @click="routerIndex">
                  <p style="font-size: 20px" class="el-icon-share"></p>
                  <p>分享</p>
                </el-link>
              </div>
              <div>
                <el-link :underline="false" @click="routerIndex">
                  <p style="font-size: 20px" class="el-icon-delete"></p>
                  <p>删除</p>
                </el-link>
              </div>

            </div>
          </el-col>
          <el-col :span="6">
            <div style="text-align: right">
              <el-button type="warning" round @click="editWeibo">发布</el-button>
            </div>
          </el-col>
        </el-row>
      </el-card>
    </div>

    <div style="margin-top: 20px">
      <router-view/>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {},
      weibo: {}
    }
  },
  methods: {
    routerIndex(){
      this.$router.push("/my-index")
    },
    editWeibo() {
      this.user = JSON.parse(localStorage.getItem("user"))
      if (this.user == null) {
        this.$message.error("当前未登录！！！")
        this.$router.push("/login")
        return;
      }
      this.weibo.userId = this.user.id;
      if (this.weibo.content == null || this.weibo.content === "") {
        this.$message.error("请输入内容")
      }

      this.axios.post("http://localhost:19000/v1/weibo/add-weibo", this.qs.stringify(this.weibo))
          .then((response) => {
            if (response.data.code == 20000) {
              this.$message.success("发布成功！！！")
              setTimeout(() => {
                window.location.reload()
              }, 1000)
            }
          })

    }
  }
}
</script>


<style scoped>

.edit_div {
  display: flex;
}

.edit_div > div {
  margin-right: 20px;
}

.text_style .el-button {
  width: 68px;
  height: 35px;
}

/deep/ .el-textarea__inner {
  background-color: #f4f4f4;
  line-height: 3;
}
</style>